# -*- coding:utf8 -*-

###########################################
# Date: 05/11/11                          #
# Auteurs: Rigaut Maximilien              #
# Nom: Parallels Intelligences            #
# Version: 0.1a                           #
# Copyright 2011: Rigaut Maximilien       #
###########################################
#    This file is part of Parallels Intelligences.
#
#    Adem is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Parallels Intelligences is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Adem. If not, see <http://www.gnu.org/licenses/>.
########################################################
# LICENCE                                              #
########################################################

if __name__=='__main__' and False: print """
+--------------------------------------------------------------+
| Parallels Intelligences Copyright (C) 2011 Rigaut Maximilien |
|  is distributed in the hope that it will be useful, but      |
|  WITHOUT ANY WARRANTY; without even the implied warranty of  |
|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.        |
+--------------------------------------------------------------+
"""
#======================+
#  Modules             |
#----------------------+

import os,sys
from Tkinter import *

#- - - - - - - - - - - -
cwd=os.getcwd()
sys.path.append(cwd+'/Modules')
#- - - - - - - - - - - -

#======================+
#  Sous-Modules        |
#----------------------+

from cleverMaths import vector
execfile('./Modules/experimentGUI.py') #from experimentGUI import cuve

#----------------------+
# Initialisation       |
#- - - - - - - - - - - +

UIC_TIME=10 # Universe Internal Clock
UIP_SIZE=10 # Universe Internal Padding

#======================+
#  Fonctions internes  |
#----------------------+

#======================+
#  Classes             |
#----------------------+

class particle(object):
	"Physic Particle, move and stuff"
	def __init__(self,place=vector(0,0),move=vector(0,0),forces=[]):
		self.place=place
		self.move=move
		self.forces=forces
		self.digest()
	def digest(self):
		temp=vector(0,0)
		for force in self.forces: temp+=force
		self.forces=[]
		self.force=temp

class eParticle(particle):
	"More important particles: Charged atoms"
	def __init__(self,charge,mass,p_forces=[],place=vector(0,0),move=vector(0,0),forces=[]):
		self.charge=charge
		self.mass=mass
		self.p_forces=[]
		self.a=vector(0,0)
		particle.__init__(self,place=place,move=move,forces=forces)
	def __str__(self): return str(self.place)
	def info(self): return str("""Charge: %i \nMass: %i \nPosition: %s"""%(self.charge,self.mass,str(self.place)))
	def digest(self):
		self.forces+=self.p_forces
		particle.digest(self)
		self.a=self.force/self.mass
		self.move=self.move-self.a/UIC_TIME
		self.place+=self.move/UIC_TIME
	def interact(self,other):
		self.temp=self.place-other.place
		dist2=abs(self.temp)
		self.temp/=(1.*dist2**(1./2))
		#print self.temp
		#self.temp=vector(0,1.)
		try:
			temp=(other.charge*self.charge/dist2)
			self.forces+=[-temp*self.temp]
			other.forces+=[temp*self.temp]
		except: pass
		try:
			temp=((self.mass*other.mass)/dist2)
			self.forces+=[temp*self.temp]
			other.forces+=[-temp*self.temp]
		except: pass
		return self.forces

#======================+
#  Programme principal |
#----------------------+

if __name__=='__main__': 
	a=eParticle(12,44,place=vector(0,1))
	b=eParticle(-22,33,place=vector(44,200))
	Bac=cuve()
	Bac.particules.append(a)
	Bac.live()